#
# @lc app=leetcode.cn id=108 lang=python3
#
# [108] 将有序数组转换为二叉搜索树
#

# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
        if nums == None or len(nums) == 0: return None
        def helper(nums, left, right):
            if left > right: return None
            mid = (left + right) // 2
            node = TreeNode(nums[mid])
            node.left = helper(nums, left, mid - 1)
            node.right = helper(nums, mid + 1, right)
            return node
        return helper(nums, 0, len(nums) - 1)

# @lc code=end

